/**
 * Created by FDG282 on 2017/9/5.
 */
var ImgShow = function(btn, showBox) {
	btn.bind('click', function() {
		showBox.fadeIn(200);
		var itemHeight = $(this).parents("li.item").height();
		var btnoffset = $(this).offset();
		var btnoffsetY = btnoffset.top;
		var btnoffsetX = btnoffset.left;
		if (showBox.children('img').length >= 1) {
			showBox.removeClass("hide").css({
				"left" : btnoffsetX - 40,
				"top" : btnoffsetY - 200
			});
		} else {
			if(btn.hasClass('clear-content')) {
				showBox.removeClass("hide").css({
					"left" : btnoffsetX - 13,
					"top" : btnoffsetY - itemHeight - 100
				});
			}else {
				showBox.removeClass("hide").css({
					"left" : btnoffsetX - 40,
					"top" : btnoffsetY - itemHeight + 30
				});
			}
		}
	});
};
// 分享微信二维码显示
function wechatImgShow() {
	// title上的分享显示二维码
	var flag = true;
	ImgShow($(".title_fx_btn"), $("#wechat_img"));
	$(".title_fx_btn").click(function() {
		if (flag) {
			var goods_id = [];
			$('#enable_ul_list').children('li').each(function() {
				goods_id.push($(this).attr('data-goods'));
			});
			$.post('/customer/save-collection', {
				goods_id : goods_id
			}, success, 'json');
			return flag = false;
			function success(data) {
				if (data.code == 200) {
					var qrcode_url = data.val;
					$('#qrcode_url').attr('src', qrcode_url);
				}
			}
		} else {
			$('#wechat_img').hide();
			return flag = true;
		}
	});
	$(".user_hart_content .item")
			.each(
					function() {
						// ImgShow($(this).find('.del_btn'), $("#usk_del"));
						$(this)
								.find(".fx_btn")
								.focus(
										function() {
											$('#qrcode').empty();
											$('.wechat_fx_layer').hide();
											if ($('#usk_del').show()) {
												$('#usk_del').hide();
											}

											var goods = $(this)
													.parents('.item').attr(
															'data-goods');

											// 判断是否已经有二维码图片
											var img_code = $(this).parents(
													'.item').find(
													'.wechat_fx_layer').find(
													'img').length;
											if (img_code == 0) {
												$('#qrcode')
														.qrcode(
																{
																	render : "canvas",
																	width : 110,
																	height : 100,
																	text : shareUrlLink
																			+ "/goods/goods-detail?goods_id="
																			+ goods
																});

												var qr_canvas = document
														.getElementsByTagName('canvas')[0];

												var img = convertCanvasToImage(qr_canvas);

												$(this).parents('.item').find(
														'.wechat_fx_layer')
														.append(img);
											}

											$(this).parents('.item').find(
													'.wechat_fx_layer').fadeIn(
													100).parents('.item')
													.siblings('.item').find(
															'.wechat_fx_layer')
													.hide();
										});

						// 离开分享按钮隐藏
						$(this).find(".fx_btn").blur(function() {
							$('.wechat_fx_layer').hide()
						});

						// 删除
						/*
						 * $(this).find(".del_btn").click(function () { var
						 * goods = $(this).parents('.item').attr('data-goods');
						 * if( $('.wechat_fx_layer').show()){
						 * $('.wechat_fx_layer').hide(); } var $that = $(this);
						 * $("#del").on('click',function () {
						 * $.post('/customer/del-collection',{goods_id:goods},success,'json');
						 * return false; function success(data){ if(data.code ==
						 * 200){ //回传当前li的ID给后台
						 * $that.parents("li.item").remove(); var count =
						 * parseInt($("#hart-count").text()); count--;
						 * $("#hart-count").text(count);
						 * $('#collection_count').text(count);
						 * $("#del").parents("#usk_del").fadeOut(200);
						 * $('.wechat_fx_layer').fadeOut(200); } } });
						 * $("#nodel").on('click',function () {
						 * $(this).parents("#usk_del").fadeOut(200); }) })
						 */
					});
}
// 筛选器

function delCollection() {
	$("#nodel").on('click', function() {
		$(this).parents("#usk_del").fadeOut(200);
	});

	$("#enable_ul_list .item").each(function(){
		var $that = $(this);
		$(this).find(".del_btn").click(function() {
			var goods = $(this).parents('#enable_ul_list .item').attr('data-goods');
			// $that.find('.shadebox-del').removeClass('hide');
			// $that.siblings('.item').find('.shadebox-del').addClass('hide');

			// $that.find('.del-btn-no').click(function(){
			// 	$that.find('.shadebox-del').addClass('hide');
			// })
			// $that.find(".del-btn-ok").on('click', function() {
			// 	$that.find('.shadebox-del').addClass('hide');
				$.ajax({
					type: 'POST',
					data:{'goods_id': goods},
					url: '/customer/del-collection',
					dataType: 'json',
					success: function(data){
						if(200==data.code){
							$that.addClass('hide').next().removeClass('hide');
                            $('#collection_count').text($('#collection_count').text()-1);
                            $('#hart-count').text( $('#hart-count').text()-1);
							return;
						}
					},
					error: function(){//后台异常
						
					}
				// });



				// for(var i = 0; i < _arr.length; i++) {
				// 	// if(_arr[i].attr('data-goods') != $that.attr('data-goods')) {
				// 		// }
				// 	}
				// 	_arr.push($that);

				// console.log(_arr)
				// $that.addClass('hide').next().removeClass('hide').find('.enable-cx-btn').click(function(){
				// 	$that.removeClass('hide').next().addClass('hide');
				// 	for(var i = 0; i < _arr.length; i++) {
				// 		console.log($that.attr('data-goods'))
				// 		console.log(_arr[i].attr('data-goods'))
	
				// 		if(_arr[i].attr('data-goods') == $that.attr('data-goods')) {
				// 			// _arr.remove(_arr[i]);
				// 			// _arr.splice($.inArray('_arr[i]',_arr),1);
				// 		}
				// 	}
				// 	console.log(_arr);
					
					
				// });

				
				// if(window.onbeforeunload){
				// 	alert(1)
				// }	
				// if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey) 
				// 	{ 
				// 		alert("你关闭了浏览器"); 
				// 	} 
					
				// $.post('/customer/del-collection', {
				// 	goods_id : goods
				// }, success, 'json');
				// return false;
				// function success(data) {
				// 	if (data.code == 200) {
				// 		$that.parents('#enable_ul_list .item').css('height','91px');
				// 		// 回传当前li的ID给后台
				// 		$that.parents("li.item").html(
				// 			'<h4 class="cx-h4">'+
				// 				'<span class="icon country_icon">'+
				// 					'<img style="width:28px;" src="http://test-static.jdstb.com/uploads/2017-12-01/151209582747644.jpg">'+
				// 				'</span>'+
				// 				'<a href="/goods/goods-detail?goods_id=12089">AMERICAN LEATHER</a>'+
				// 			'</h4>'+
				// 			'<a href="/goods/goods-detail?goods_id=12125">'+
				// 				'<p class="cx-h6"><span>搭配床品靠垫</span> 拜占庭系列</p>'+
				// 			'</a>'+
				// 			'<div class="cx-cx">'+
				// 				'<span class="cx-icon-ok"></span>'+
				// 				'<span class="cx-ok">已删除</span>'+
				// 				'<span class="cx-btn enable-cx-btn" onclick="cxEndble()">撤销</span>'+
				// 			'</div>');
				// 		var count = parseInt($("#hart-count").text());
				// 		var _list_item = $('#enable_ul_list').find('.item');
				// 		count--;
				// 		$("#hart-count").text(count);
				// 		$('#collection_count').text(_list_item.length);
				// 		$("#del").parents("#usk_del").fadeOut(200);
				// 		$('.wechat_fx_layer').fadeOut(200);
				// 		//mod FDG416 2018/03/21 ID544 【商城需求】心愿单界面无商品时，有提示且去除分享按钮 start
				// 		no_goods();
				// 		//mod FDG416 2018/03/21 ID544 【商城需求】心愿单界面无商品时，有提示且去除分享按钮 end
				// 	}
				// }
			});			
			// $("#nodel").on('click', function() {
			// 	$(this).parents("#usk_del").fadeOut(200);
			// })
		});
		
	})

    $("#disable_ul_list .item").each(function(){
        var $that = $(this);
        $(this).find(".del_btn").click(function() {
            var goods = $(this).parents('#disable_ul_list .item').attr('data-goods');
            // $that.find('.shadebox-del').removeClass('hide');
            // $that.siblings('.item').find('.shadebox-del').addClass('hide');

            // $that.find('.del-btn-no').click(function(){
            //     $that.find('.shadebox-del').addClass('hide');
            // })
            // $that.find(".del-btn-ok").on('click', function() {
            //     $that.find('.shadebox-del').addClass('hide');
                $.ajax({
                    type: 'POST',
                    data:{'goods_id': goods},
                    url: '/customer/del-collection',
                    dataType: 'json',
                    success: function(data){
                        if(200==data.code){
                            $that.addClass('hide').next().removeClass('hide');
                            //$('#collection_count').text($('#collection_count').text()-1);
                            //$('#hart-count').text( $('#hart-count').text()-1);
                            return;
                        }
                    },
                    error: function(){//后台异常

                    }
                // });



                // for(var i = 0; i < _arr.length; i++) {
                // 	// if(_arr[i].attr('data-goods') != $that.attr('data-goods')) {
                // 		// }
                // 	}
                // 	_arr.push($that);

                // console.log(_arr)
                // $that.addClass('hide').next().removeClass('hide').find('.enable-cx-btn').click(function(){
                // 	$that.removeClass('hide').next().addClass('hide');
                // 	for(var i = 0; i < _arr.length; i++) {
                // 		console.log($that.attr('data-goods'))
                // 		console.log(_arr[i].attr('data-goods'))

                // 		if(_arr[i].attr('data-goods') == $that.attr('data-goods')) {
                // 			// _arr.remove(_arr[i]);
                // 			// _arr.splice($.inArray('_arr[i]',_arr),1);
                // 		}
                // 	}
                // 	console.log(_arr);


                // });


                // if(window.onbeforeunload){
                // 	alert(1)
                // }
                // if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)
                // 	{
                // 		alert("你关闭了浏览器");
                // 	}

                // $.post('/customer/del-collection', {
                // 	goods_id : goods
                // }, success, 'json');
                // return false;
                // function success(data) {
                // 	if (data.code == 200) {
                // 		$that.parents('#enable_ul_list .item').css('height','91px');
                // 		// 回传当前li的ID给后台
                // 		$that.parents("li.item").html(
                // 			'<h4 class="cx-h4">'+
                // 				'<span class="icon country_icon">'+
                // 					'<img style="width:28px;" src="http://test-static.jdstb.com/uploads/2017-12-01/151209582747644.jpg">'+
                // 				'</span>'+
                // 				'<a href="/goods/goods-detail?goods_id=12089">AMERICAN LEATHER</a>'+
                // 			'</h4>'+
                // 			'<a href="/goods/goods-detail?goods_id=12125">'+
                // 				'<p class="cx-h6"><span>搭配床品靠垫</span> 拜占庭系列</p>'+
                // 			'</a>'+
                // 			'<div class="cx-cx">'+
                // 				'<span class="cx-icon-ok"></span>'+
                // 				'<span class="cx-ok">已删除</span>'+
                // 				'<span class="cx-btn enable-cx-btn" onclick="cxEndble()">撤销</span>'+
                // 			'</div>');
                // 		var count = parseInt($("#hart-count").text());
                // 		var _list_item = $('#enable_ul_list').find('.item');
                // 		count--;
                // 		$("#hart-count").text(count);
                // 		$('#collection_count').text(_list_item.length);
                // 		$("#del").parents("#usk_del").fadeOut(200);
                // 		$('.wechat_fx_layer').fadeOut(200);
                // 		//mod FDG416 2018/03/21 ID544 【商城需求】心愿单界面无商品时，有提示且去除分享按钮 start
                // 		no_goods();
                // 		//mod FDG416 2018/03/21 ID544 【商城需求】心愿单界面无商品时，有提示且去除分享按钮 end
                // 	}
                // }
            });
            // $("#nodel").on('click', function() {
            //     $(this).parents("#usk_del").fadeOut(200);
            // })
        });

    })
}
function searchShow() {
	var searchBtn = function(btn, box) {
		btn.bind("click", function() {
			if (box.is('.hide')) {
				box.removeClass('hide');
			} else {
				box.addClass('hide');
			}
		})
	};
	var searchInput = $(".user_search_value");
	searchBtn($(".js_select"), $(".user_hart_select_list"));
	searchBtn($(".js_show_val"), searchInput);
	if (searchInput.show()) {
		$(".js_show_val").click(function() {
			var $val = searchInput.val();
			if ($val != "") {
				getGoods();
			}
		})
	} else {
		searchBtn($(".js_show_val"), searchInput);
	}

	$('#category-list-form').on('click', '.item', function() {
        var li_sort_type = $(this).attr('data-sort-type');
        var sort_type = $('#sort_type').val();
        var sort_val = $('#sort_val').val();

        if(li_sort_type == 'default'){
            $('#sort_val').val(2);
            $('.user_hart_select_list .item span').html('');
        }else{
            $('#icon_'+li_sort_type).empty();
            if(li_sort_type == sort_type && sort_val == 1){
                $('#sort_val').val(2);
                $('#icon_'+li_sort_type).html('↓');
            }else{
                $('.user_hart_select_list .item span').html('');
                $('#sort_val').val(1);
                $('#icon_'+li_sort_type).html('↑');
            }
        }
        $('#sort_type').val(li_sort_type);
		getGoods();
	});
}

function getGoods() {
	var search_keyword = $('#search_keyword').val();
	var sort_type = $('#sort_type').val();
	var sort_val = $('#sort_val').val();
	$.post('/customer/get-collection', {
		sort_type : sort_type,
		sort_val : sort_val,
		search_keyword : search_keyword
	}, success, 'json');
	return false;
	function success(data) {
		if (data.code == 200) {
			var count = data.val.count;
			$('#collection_count').html(count);
			pushData(data.val);
			wechatImgShow();
			delCollection();
		}
		if (data.code == 500) {
			window.location.href = data.url;
		}
		//mod FDG416 2018/03/21 ID544 【商城需求】心愿单界面无商品时，有提示且去除分享按钮 start
		no_goods();
		if($('#disable_ul_list').children('li').length < 1) {
			$('.user_hart_lost').hide();
		}
		//mod FDG416 2018/03/21 ID544 【商城需求】心愿单界面无商品时，有提示且去除分享按钮 end
	}
}

function pushData(goods) {
	var image_bath_url = $('#image_bath_url').val();
	var enable_data = goods['enable'];
	var disable_data = goods['disable'];
	$('#enable_ul_list').empty();
	if (enable_data.length > 0) {
		var html = '';

		for (var i = 0; i < enable_data.length; i++) {
			html += '<li class="item itemb cx_item_'+enable_data[i]['goods_id']+'" data-goods="'
					+ enable_data[i]['main_goods_id'] + '">';
			html += '<div class="item_img">';
			html += '<a href="/goods/goods-detail?goods_id='+enable_data[i]['main_goods_id']+'"><img src="' + image_bath_url + '/'
					+ enable_data[i]['goods_main_pic'] + '" title="'
					+ enable_data[i]['goods_pic_title'] + '" alt="'
					+ enable_data[i]['goods_pic_title'] + '"/></a>';
			html += '</div>';
			html += '<div class="item_info">';
			html += '<h4 class="h4">';
            if(enable_data[i]['country_icon'] != '' && enable_data[i]['country_icon'] != null){
                html += '<span class="icon country_icon">';
                html += '<img style="width:28px;" src="' + image_bath_url + '/' + enable_data[i]['country_icon'] + '"/></span>';
            }
			html += '<a href="/goods/goods-detail?goods_id='+enable_data[i]['main_goods_id']+'">' + enable_data[i]['brand_name'] + '</a></h4>';
            //mod by huangzhao 20180117 460 【商城需求】系列名与商品名称的位置对调 start
			//html += '<h6 class="h6"><span>' + enable_data[i]['series']
			//		+ '</span><a href="/goods/goods-detail?goods_id='+enable_data[i]['main_goods_id']+'"> ' + enable_data[i]['goods_name_cn'] + '</a></h6>';
			/*mod FDG416 2018/03/10 ID536 【商城优化】火狐/IE兼容性 start */ 
            html += '<a href="/goods/goods-detail?goods_id='+enable_data[i]['main_goods_id']+'"><p class="h6"><span>' + enable_data[i]['goods_name_cn'] + '</span> ' + enable_data[i]['series'] + '</p></a>';
			/*mod FDG416 2018/03/10 ID536 【商城优化】火狐/IE兼容性 end */ 
            //mod by huangzhao 20180117 460 【商城需求】系列名与商品名称的位置对调 end
			//add by huangzhao 20180118 461 【商城需求】点击商品图片、国家图标、品牌、商品名称、系列名、价格，都能链接至商品详情页 start
			
			// mod FDG416 2018/3/16 ID540 【商城需求】心愿单PC页面改版 start
            html += '<a href="/goods/goods-detail/goods_id/'+enable_data[i]['main_goods_id']+'" class="commodity-number"> 商品编号：';
			html += '<span>'+enable_data[i]['sku']+'</span>';
			html += '</a>';
			// mod FDG416 2018/3/16 ID540 【商城需求】心愿单PC页面改版 end
			

            html += '<a href="/goods/goods-detail/goods_id/'+enable_data[i]['main_goods_id']+'">';
            //add by huangzhao 20180118 461 【商城需求】点击商品图片、国家图标、品牌、商品名称、系列名、价格，都能链接至商品详情页 end
			html += returnPriceHtml(enable_data[i]);
            html += '</a>';
            if(enable_data[i]['activity_message']){
                html += '<ul class="activity_message_ul">';
                for (var s = 0; s < enable_data[i]['activity_message'].length; s++) {
                    html += '<li class="activity_message_li activity_message_'+enable_data[i]['activity_message'][s]['activity_identification_style']+'">'
                    + '<span class="activity_message_span_one">'+enable_data[i]['activity_message'][s]['activity_identification']+'</span>'
                    + '</li>';
                }
                html +='</ul>';
            }

			html += '</div>';
			html += '<div class="item_btns">';
			html += '<p class="time">添加日期: <span>'
					+ enable_data[i]['create_time'] + '</span></p>';
			html += '<a class="link-more fx_btn" href="javascript:;">分享</a> ';
			html += '<a class="link-more del_btn" href="javascript:;">删除</a>';
					// '<div class="hartList_del_layer shadebox-del hide">'+
					// 	'<p>确定要删除？</p>'+
					// 	'<button type="button" class="link-more del-btn-ok">删除</button>'+
					// 	'<button type="button" class="link-more del-btn-no">取消</button>'+
					// '</div></div>';
			html += '<div class="wechat_fx_layer shadebox" ><h2>分享到微信</h2></div></li>';

			html += '<li class="item cx-item cx_item_hide_'+enable_data[i]['goods_id']+' hide">';
            html += '<h4 class="cx-h4">';
            if(enable_data[i]['country_icon'] != '' && enable_data[i]['country_icon'] != null) {
                html += '<span class="icon country_icon">' +
                '<img style="width:28px;" src="' + image_bath_url + '/' + enable_data[i]['country_icon'] + '">' +
                '</span>';
            }
            html +=	'<a href="/goods/goods-detail/goods_id/'+enable_data[i]['main_goods_id']+'">'+enable_data[i]['brand_name']+'</a>'+
						'</h4>';
            html += '<a href="/goods/goods-detail/goods_id/'+enable_data[i]['main_goods_id']+'">'+
							'<p class="cx-h6"><span>'+enable_data[i]['goods_name_cn']+'</span> '+enable_data[i]['series']+'</p>'+
						'</a>'+
						'<div class="cx-cx">'+
							'<span class="cx-icon-ok"></span>'+
							'<span class="cx-ok">已删除</span>'+
							'<span class="enable-cx-btn cx-btn" onclick="reDel('+enable_data[i]['goods_id']+','+1+',\''+enable_data[i]['insert_time']+'\')" >撤销</span>'+
						'</div>'
					'</li>';
		}
		$('#enable_ul_list').append(html);
	}else {
		//mod FDG416 2018/03/21 ID544 【商城需求】心愿单界面无商品时，有提示且去除分享按钮 start
		no_goods();
	}
	//mod FDG416 2018/03/21 ID544 【商城需求】心愿单界面无商品时，有提示且去除分享按钮 end
	$('#disable_ul_list').empty();
	if (disable_data.length > 0) {
		var html = '';
		for (var i = 0; i < disable_data.length; i++) {
			html += '<li class="item cx_item_'+disable_data[i]['goods_id']+'" data-goods="'
					+ disable_data[i]['main_goods_id'] + '">';
			html += '<div class="item_img pr">';
			html += '<img src="' + image_bath_url + '/'
					+ disable_data[i]['goods_main_pic'] + '" title="'
					+ disable_data[i]['goods_pic_title'] + '" alt="'
					+ disable_data[i]['goods_pic_alt'] + '"/>';
			html += '<span class="span-invalid pa">已失效</span>';
			html += '</div>';
			html += '<div class="item_info">';
			html += '<h4 class="h4">';
            if(disable_data[i]['country_icon'] != '' && disable_data[i]['country_icon'] != null){
                html += '<span class="icon country_icon">';
                html += '<img style="width:28px;" src="' + image_bath_url + '/' + disable_data[i]['country_icon'] + '"/></span>';
            }
			html += disable_data[i]['brand_name'] + '</h4>';
            //mod by huangzhao 20180117 460 【商城需求】系列名与商品名称的位置对调 start
			//html += '<h6 class="h6"><span>' + disable_data[i]['series']
			//		+ '</span> ' + disable_data[i]['goods_name_cn'] + '</h6>';
			/*mod FDG416 2018/03/10 ID536 【商城优化】火狐/IE兼容性 start */ 
            html += '<p class="h6"><span>' + disable_data[i]['goods_name_cn'] + '</span> ' + disable_data[i]['series'] + '</p>';
			/*mod FDG416 2018/03/10 ID536 【商城优化】火狐/IE兼容性 end */ 
			//mod by huangzhao 20180117 460 【商城需求】系列名与商品名称的位置对调 end

			// mod FDG416 2018/3/16 ID540 【商城需求】心愿单PC页面改版 start
			html += '<a href="/goods/goods-detail/goods_id/'+disable_data[i]['main_goods_id']+'" class="commodity-number"> 商品编号：';
			html += '<span>'+disable_data[i]['sku']+'</span>';
			html += '</a>';
			
			html += returnPriceHtml(disable_data[i]);
            // if(disable_data[i]['activity_message']){
				//     html += '<ul class="activity_message_ul">';
				//     for (var s = 0; s < disable_data[i]['activity_message'].length; s++) {
					//         html += '<li class="activity_message_li activity_message_'+disable_data[i]['activity_message'][s]['activity_identification_style']+'">'
					//         + '<span class="activity_message_span_one">'+disable_data[i]['activity_message'][s]['activity_identification']+'</span>'
					//         + '</li>';
					//     }
					//     html +='</ul>';
					// }
			// mod FDG416 2018/3/16 ID540 【商城需求】心愿单PC页面改版 end
			html += '</div>';
			html += '<div class="item_btns">';
			html += '<p class="time">添加日期: <span>'
					+ disable_data[i]['create_time'] + '</span></p>';
			html += '<a class="fx_btn_no" href="javascript:;">分享</a> ';
			html += '<a class="link-more del_btn" href="javascript:;">删除</a>';
					// '<div class="hartList_del_layer shadebox-del hide">'+
					// 	'<p>确定要删除？</p>'+
					// 	'<button type="button" class="link-more del-btn-ok">删除</button>'+
					// 	'<button type="button" class="link-more del-btn-no">取消</button>'+
					// '</div></div>';
			html += '<div class="wechat_fx_layer shadebox" ><h2>分享到微信</h2></div></li>';
            html += '<li class="item cx-item cx_item_hide_'+disable_data[i]['goods_id']+' hide">'+
            '<h4 class="cx-h4">';
            if(disable_data[i]['country_icon'] != '' && disable_data[i]['country_icon'] != null) {
                html += '<span class="icon country_icon">' +
                '<img style="width:28px;" src="' + image_bath_url + '/' + disable_data[i]['country_icon'] + '">' +
                '</span>';
            }
            html += '<a href="/goods/goods-detail/goods_id/'+disable_data[i]['main_goods_id']+'">'+disable_data[i]['brand_name']+'</a>'+
            '</h4>'+
            '<a href="/goods/goods-detail/goods_id/'+disable_data[i]['main_goods_id']+'">'+
            '<p class="cx-h6"><span>'+disable_data[i]['goods_name_cn']+'</span> '+disable_data[i]['series']+'</p>'+
            '</a>'+
            '<div class="cx-cx">'+
            '<span class="cx-icon-ok"></span>'+
            '<span class="cx-ok">已删除</span>'+
            '<span class="enable-cx-btn cx-btn" onclick="reDel('+disable_data[i]['goods_id']+','+false+',\''+disable_data[i]['insert_time']+'\')" >撤销</span>'+
            '</div>'
            '</li>';
		}
		$('#disable_ul_list').append(html);
	}else {
		$('.user_hart_lost').hide();
	}
}

function returnPriceHtml(data){
	var html = '';
	switch (parseInt(data['hidden_price'])){
		case SHOW_DETAIL_PRICE:
			if(parseInt(data['market_price']) == 0 || data['market_price'] == data['sale_price']){
				html += '<p class="item_price">'+data['unit'] + data['sale_price']+'</p>';
			}else{
				/* mod FDG416 2018/1/29 ID486 【商城需求】商品列表页文字颜色与排版修改 start */
				html += '<p class="item_price">'
				+ data['unit'] + data['sale_price']
				+'<del>' + data['unit']
				+ data['market_price'] + '</del>'
				+ '</p>';
				/* mod FDG416 2018/1/29 ID486 【商城需求】商品列表页文字颜色与排版修改 end */
			}
			break;
		case HIDE_DETAIL_PRICE:
            html += '<p class="item_price">'+REQUIRE_ARTIFICIAL+'</p>';
			break;
		case ADD_MARKET_PRICE_QI:
            if(parseInt(data['market_price']) == 0 || data['market_price'] == data['sale_price']){
				html += '<p class="item_price">'+data['unit'] + data['sale_price']+PRICE_SUFFIX+'</p>';
			}else{
				/* mod FDG416 2018/1/29 ID486 【商城需求】商品列表页文字颜色与排版修改 start */
				html += '<p class="item_price">'
				+ data['unit'] + data['sale_price']
				+'<del>' + data['unit']
				+ data['market_price']+PRICE_SUFFIX + '</del>'
				+ '</p>';
				/* mod FDG416 2018/1/29 ID486 【商城需求】商品列表页文字颜色与排版修改 end */
			}
			break;
		case ADD_SALE_PRICE_QI:
            if(parseInt(data['market_price']) == 0 || data['market_price'] == data['sale_price']){
				html += '<p class="item_price">'+data['unit'] + data['sale_price']+'</p>';
			}else{
				/* mod FDG416 2018/1/29 ID486 【商城需求】商品列表页文字颜色与排版修改 start */
				html += '<p class="item_price">'
				+ data['unit'] + data['sale_price']+PRICE_SUFFIX
				+'<del>' + data['unit']
				+ data['market_price'] + '</del>'
				+ '</p>';
				/* mod FDG416 2018/1/29 ID486 【商城需求】商品列表页文字颜色与排版修改 end */
			}
			break;
		case ADD_PRICE_QI:
            if(parseInt(data['market_price']) == 0 || data['market_price'] == data['sale_price']){
				html += '<p class="item_price">'+data['unit'] + data['sale_price']+PRICE_SUFFIX+'</p>';
			}else{
				/* mod FDG416 2018/1/29 ID486 【商城需求】商品列表页文字颜色与排版修改 start */
				html += '<p class="item_price">'
				+ data['unit'] + data['sale_price']+PRICE_SUFFIX
				+'<del>' + data['unit']+ data['market_price']+PRICE_SUFFIX + '</del>'
				+ '</p>';
				/* mod FDG416 2018/1/29 ID486 【商城需求】商品列表页文字颜色与排版修改 end */
			}
			break;
	}
	return html;
}

function convertCanvasToImage(canvas) {
	// 新Image对象，可以理解为DOM
	var image = new Image();
	// canvas.toDataURL 返回的是一串Base64编码的URL，当然,浏览器自己肯定支持
	// 指定格式 PNG
	image.src = canvas.toDataURL("image/png");
	return image;
}

searchShow();
// wechatImgShow();
delCollection();

//mod FDG416 2018/03/21 ID544 【商城需求】心愿单界面无商品时，有提示且去除分享按钮 start
function no_goods(){
	if($('#enable_ul_list').children('li').length < 1) {
		var html = '';
		html += '<div class="no-goods">暂无商品！</div>'
		$('.title_fx_btn').addClass('hide');
		$('#enable_ul_list').html(html);
	}
}
//mod FDG416 2018/03/21 ID544 【商城需求】心愿单界面无商品时，有提示且去除分享按钮 end


// add FDG416 2018/3/20 ID542 【商城需求】心愿单界面增加预约到店功能，点击预约到店，新增页面填写用户信息 start
$(function(){
	// mod FDG416 2018/03/23 ID545 【商城需求】心愿单页面有效商品删除后，可在撤销，原有效商品删除效果去除；可对失效商品全部删除 start
	ImgShow($(".clear-content"), $("#qc_del"));
	$('#qc_del > #nodel-q').click(function(){
		$(this).parents("#qc_del").fadeOut(200);
	})
	$('#qc_del > #del-q').click(function(){
		$('#disable_ul_list').html('');
		$.post('/customer/del-all-no-use-goods', {}, success, 'json');
		return false;
		function success(data) {
				if (data.code == 200) {
					$("#del-q").parents("#qc_del").fadeOut(200);
					$('#disable_ul_list').html('');
					$('.user_hart_lost').hide();
                    //$('#hart-count').text(parseInt($('#hart-count').text())-data.data.count);
				}
			}
		})
	// mod FDG416 2018/03/23 ID545 【商城需求】心愿单页面有效商品删除后，可在撤销，原有效商品删除效果去除；可对失效商品全部删除 end

	// 点击打印心愿单异步请求
	$('.title_print').mouseover(function(){
		if($('.title_print').attr('href')=='javascript:;') {
			$('.title_print').attr('href',PRINT_LIST);
			$('.title_print').mousedown(function(){
				if($('.title_print').data('num') == '0') {
					$.ajax({
						type: 'POST',
						url: '/customer/print-info-date',
						dataType: 'json',
						success: function(data){
							if(200==data.code){
								
							}
						},
						error: function(){//后台异常
							
						}
					});
					$('.title_print').data('num','1');
				}else {
					return;
				}
			})
		}
	})
	//调用日期插件
	$(".data-select").flatpickr({
		minDate:'today'
	});
	// 点击预约到店出现弹层
	$('.bespeak-btn').on('click',function(){
		$(".bespeak-form").removeClass('hide');
		var config_value = $(this).attr('data-config-value');
		$('.vip_form').find('select[name=service_vip]').val(config_value);
		layer.open({
			type: 1,
			title: false,
			closeBtn:1,
			shadeClose: false,
			skin: '.bespeak-form',
			content: $('.bespeak-form'),
			success:function(index){
				$('html').css('overflow-y', 'hidden');
				$('.layui-layer-close').bind('click',function(){
					layer.closeAll();
					$('html').css('overflow-y', 'auto');
					$(".bespeak-form").addClass('hide');
				});
			}
		});
	});
	// 联系人
	$('.bespeak-name').blur(function(){
		var _val = $(this).val();
		if(_val.trim() == '') {
			$(this).addClass('border-F9BBC0');
		}else {
			$(this).removeClass('border-F9BBC0');
		}
	})
	// 联系电话
	$('.bespeak-Telephone').blur(function(){
		var _val2 = $(this).val();
		var reg = /^\d{11}$|\d{3}-\d{8}|\d{4}-\d{7,8}/;
		if(_val2.trim() == '' || !reg.test(_val2)) {
			$(this).addClass('border-F9BBC0');
		}else {
			$(this).removeClass('border-F9BBC0');
		}
	})
	// 选择时间段
	$('.div-time').focus(function(){
		$('.time-select').removeClass('hide');
		$(this).css('border','1px solid #C9C9C9');
	})
	$('.time-select').find('p').click(function(){
		$('#flatpickr-time').val($(this).text());
		$('.time-select').addClass('hide');
	})

	$('body').click(function(e){
		var target_time_select = $(e.target).is('#time-select *');
		if(e.target.id != 'flatpickr-time' && !target_time_select) {
			$('.time-select').addClass('hide');
			$('.div-time').css('border','1px solid #fff');
		}
   })
	// 预约按钮
	$('.btn-form').click(function(){
		var reserv_name = $('.bespeak-name').val();
		var reserv_mobile = $('.bespeak-Telephone').val();
		var reserv_time = $("input[ name='flatpickr-tryme']").val();
		var reserv_time_ex = $('#flatpickr-time').val();
		if(reserv_name.trim() == '') {
			$('.bespeak-name').addClass('border-F9BBC0');
			return false;
		}else {
			$('.bespeak-name').removeClass('border-F9BBC0');
		}
		if(reserv_mobile.trim() == '' || $('.bespeak-Telephone').hasClass('border-F9BBC0')) {
			$('.bespeak-Telephone').addClass('border-F9BBC0');
			return false;
		}else {
			$('.bespeak-Telephone').removeClass('border-F9BBC0');
		}

		$.ajax({
			type: 'POST',
			data:{
				'reserv_name':reserv_name,
				'reserv_mobile':reserv_mobile,
				'reserv_time':reserv_time,
				'reserv_time_ex':reserv_time_ex
			},
			url: '/customer/appointment',
			dataType: 'json',
			success: function(data){
				if(200==data.code){
					$('#bespeak-form-btn').addClass('hide');
					$('.bespeak-ok').removeClass('hide');
				}else{
					$('#bespeak-form-btn').addClass('hide');
					$('.bespeak-no').removeClass('hide');
					$('.brspeak-back').click(function(){
						$('.bespeak-no').addClass('hide');
						$('#bespeak-form-btn').removeClass('hide');
					})
				}
			},
			error: function(){//后台异常
				
			}
		});
	})
})
// add FDG416 2018/3/20 ID542 【商城需求】心愿单界面增加预约到店功能，点击预约到店，新增页面填写用户信息 end


// note

function reDel(goods_id,status,insert_time){
	
	//接受参数
	if(!goods_id){
		return false;
	}
	
	$.ajax({
		type: 'POST',
		data:{
			'goods_id':goods_id,
			'use_flg':status,
			'insert_time':insert_time
		},
		url: '/customer/re-del-collection',
		dataType: 'json',
		success: function(data){
			if(200==data.code){
				$('.cx_item_'+goods_id).removeClass('hide');
				$('.cx_item_hide_'+goods_id).addClass('hide');

                //mod by FDG367 如果传值为null不考虑商品的状态 545 【商城需求】心愿单页面有效商品删除后，可在撤销，原有效商品删除效果去除；可对失效商品全部删除 start
                if(data.data.isload){
                    getGoods();
                }

                if(1==status && false==data.data.isload){
                    $('#collection_count').text(parseInt($('#collection_count').text())+1);
                    $('#hart-count').text(parseInt($('#hart-count').text())+1);
                }

                if(0==status && true==data.data.isload){
                    $('#collection_count').text(parseInt($('#collection_count').text())+1);
                    $('#hart-count').text(parseInt($('#hart-count').text())+1);
                }
			}
		},
		error: function(){//后台异常
			
		}
	});

}